<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 请输入六位数密码 -->
    <input type="password" id="input" placeholder="请输入你六位数密码">

    <script>
        var input = document.getElementById("input");
        input.onkeydown = function(){
            if(event.keyCode == 13&&this.value!=""){
                var value = this.value.trim();
                var reg = /^\d{6}$/g;               //规则在这
                console.log(reg.test(this.value));
            }
        }
    </script>

        <!-- 密码,字母开头，后面是数字，且数字不低于五位数 -->
        <input type="password" id="input2" placeholder="字母开头，后面是数字，且数字不低于五位数">

        <script>
            var input2 = document.getElementById("input2");
            input2.onkeydown = function(){
                if(event.keyCode == 13&&this.value!=""){
                    var value = this.value.trim();
                    var reg = /^[a-zA-Z]+\d{5,}$/g;     //规则在这
                    console.log(reg.test(this.value));
                }
            }
        </script>

        <!-- 用户名，只能是字母，大小写不限，不能超过八个字符 -->
        <input type="password" id="input3" placeholder="用户名，只能是字母，大小写不限，不能超过八个字符">

        <script>
            var input3 = document.getElementById("input3");
            input3.onkeydown = function(){
                if(event.keyCode == 13&&this.value!=""){
                    var value = this.value.trim();
                    var reg = /^[a-zA-Z]{1,8}$/g;     //规则在这
                    console.log(reg.test(this.value));
                }
            }
        </script>
</body>
</html>